package com.example.emailcraft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.emailcraft.entity.Countdown;
import com.example.emailcraft.mapper.CountdownMapper;
import org.springframework.stereotype.Service;

@Service
public class CountdownServiceImpl extends ServiceImpl<CountdownMapper, Countdown> {

    // 设置结束时间戳
    public void setEndTime(String uuid, Long endTime) {
        Countdown countdown = new Countdown();
        countdown.setUuid(uuid);
        countdown.setEndTime(endTime);
        // 如果 UUID 已存在，更新；否则插入新记录
        this.saveOrUpdate(countdown);
    }

    // 根据 UUID 获取结束时间戳
    public Long getEndTime(String uuid) {
        Countdown countdown = this.getOne(new QueryWrapper<Countdown>().eq("uuid", uuid));
        return countdown != null ? countdown.getEndTime() : 0L;
    }
}